package com.example.springbott.wx_service;

import com.example.springbott.bean.*;
import com.example.springbott.mapper.*;
import com.example.springbott.util.Count;
import com.example.springbott.utils.HandleOptionUtil;
import com.example.springbott.wx_bean_heheer.*;
import com.example.springbott.wx_bean_heheer.order.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.gson.Gson;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @author 1784549954@qq.com
 * @since 2022/11/22 10:55
 */
@Service
public class OrderServiceImpl implements OrderService {
    private final static String USER_ID = "1";
    private static final String REFUND_TYPE = "微信接口退款";
    private static final String REFUND_CONTENT = null;


    @Autowired
    MarketOrderMapper marketOrderMapper;

    @Autowired
    MarketCommentMapper marketCommentMapper;

    @Autowired
    MarketCartMapper marketCartMapper;

    @Autowired
    MarketAddressMapper marketAddressMapper;

    @Autowired
    MarketCouponMapper marketCouponMapper;

    @Autowired
    MarketCouponUserMapper marketCouponUserMapper;

    @Autowired
    MarketGrouponRulesMapper marketGrouponRulesMapper;

    @Autowired
    MarketGoodsMapper marketGoodsMapper;

    @Autowired
    MarketOrderGoodsMapper marketOrderGoodsMapper;

    @Autowired
    MarketSystemMapper marketSystemMapper;




    @Override
    public OrderListVODate orderList(OrderListBO orderListBO) {
        PageHelper.startPage(orderListBO.getPage(), orderListBO.getLimit());

        //获取UserId查询订单表
        //订单状态
        //待付款 101
        //代发货 201
        //待收货 301
        //待评价 401
        //根据userid查询可见订单表中的数据
//        List<DateTest1> dateTest = marketOrderMapper.selectOrder("1");
////        List<DateTest1> dateTest2 = marketOrderMapper.selectOrderNotrep("1");
//        PageInfo<DateTest1> pageInfo = new PageInfo<>(dateTest);
//        OrderListVODate orderListVODate = new OrderListVODate();
//        orderListVODate.setLimit(pageInfo.getSize());
//        orderListVODate.setPage(pageInfo.getPageNum());
//        orderListVODate.setTotal((int) pageInfo.getTotal());
//        orderListVODate.setPages(pageInfo.getPages());
//
//        ArrayList<OrderListVODate.ListBean> listBeans = new ArrayList<>();
//        HashSet<Integer> integers = new HashSet<>();
//        for (DateTest1 dateTest1 : dateTest) {
//            if (!integers.contains(dateTest1.getId())) {
//            OrderListVODate.ListBean listBean = new OrderListVODate.ListBean();
//            listBean.setOrderStatusText(dateTest1.getOrderStatusText());
//            listBean.setAftersaleStatus(dateTest1.getAftersaleStatus());
//            listBean.setIsGroupin(dateTest1.getIsGroupin());
//            listBean.setOrderSn(dateTest1.getOrderSn());
//            listBean.setActualPrice(dateTest1.getActualPrice());
//            listBean.setId(dateTest1.getId());
//            ArrayList<OrderListVODate.ListBean.GoodsListBean> goodsListBeans = new ArrayList<>();
//            listBean.setGoodsList(goodsListBeans);
//
//                listBeans.add(listBean);
//                listBean.setHandleOption(new OrderListVODate.ListBean.HandleOptionBean());
//                integers.add(dateTest1.getId());
//            }
//
//        }
//
//        for (OrderListVODate.ListBean listBean : listBeans) {
//            ArrayList<OrderListVODate.ListBean.GoodsListBean> goodsLists = new ArrayList<>();
//            for (DateTest1 dateTest1 : dateTest) {
//
//                if (dateTest1.getId() == listBean.getId()) {
//                    OrderListVODate.ListBean.GoodsListBean goodsListBean = new OrderListVODate.ListBean.GoodsListBean();
//                    goodsListBean.setGoodsName(dateTest1.getGoodsName());
//                    goodsListBean.setNumber(dateTest1.getNumber());
//                    goodsListBean.setPicUrl(dateTest1.getPicUrl());
//                    goodsListBean.setId(dateTest1.getInnerId());
//                    goodsLists.add(goodsListBean);
//                }
//
//            }
//            listBean.setGoodsList(goodsLists);
//
//        }
//        orderListVODate.setList(listBeans);
//        return orderListVODate;

        MarketUser principal = (MarketUser) SecurityUtils.getSubject().getPrincipal();
        List<DateTest1> dateTest = marketOrderMapper.selectOrder(principal.getId().toString(),orderListBO);
        //遍历结果集对象给第一层属性赋值
        OrderListVODate orderListVODate = new OrderListVODate();
        PageInfo<DateTest1> pageInfo = new PageInfo<>(dateTest);
        orderListVODate.setLimit(pageInfo.getSize());
        orderListVODate.setPage(pageInfo.getPageNum());
        orderListVODate.setTotal((int) pageInfo.getTotal());
        orderListVODate.setPages(pageInfo.getPages());
        ArrayList<OrderListVODate.ListBean> listBeans = new ArrayList<>();
        LinkedList<Integer> list = new LinkedList<>();
        for (DateTest1 dateTest1 : dateTest) {
            if(!list.contains(dateTest1.getId())) {


                OrderListVODate.ListBean listBean = new OrderListVODate.ListBean();
                listBean.setOrderSn(dateTest1.getOrderSn());
                listBean.setId(dateTest1.getId());
                listBean.setActualPrice(dateTest1.getActualPrice());
                listBean.setIsGroupin(dateTest1.getIsGroupin());
                listBean.setOrderStatusText(dateTest1.getOrderStatusText());
                listBean.setAftersaleStatus(dateTest1.getAftersaleStatus());
                listBean.setHandleOption(HandleOptionUtil.getHandleOption(dateTest1.getOrderStatus()));
                ArrayList<OrderListVODate.ListBean.GoodsListBean> goodsListBeans = new ArrayList<>();
                for (DateTest1 test1 : dateTest) {
                    if (dateTest1.getId() == test1.getId()) {
                        OrderListVODate.ListBean.GoodsListBean goodsListBean = new OrderListVODate.ListBean.GoodsListBean();
                        goodsListBean.setGoodsName(test1.getGoodsName());
                        goodsListBean.setPicUrl(test1.getPicUrl());
                        goodsListBean.setNumber(test1.getNumber());
                        goodsListBean.setSpecifications(test1.getSpecifications());
                        goodsListBean.setId(test1.getInnerId());
                        goodsListBeans.add(goodsListBean);
                        goodsListBean.setPrice(test1.getPrice());
                    }
                }
                listBean.setGoodsList(goodsListBeans);
                listBeans.add(listBean);

            }

            list.add(dateTest1.getId());
        }
        orderListVODate.setList(listBeans);
        return orderListVODate;

    }

    @Override
    public OrderDetailVO OrderDetail(String orderId) {
        OrderDetailVO orderDetailVO = new OrderDetailVO();
        OrderDetailOrderInfo orderDetailOrderInfo = marketOrderMapper.orderDetailByOrderInfo(orderId);
        Integer comment = marketOrderMapper.orderDetailId(orderDetailOrderInfo.getId());
        orderDetailOrderInfo.setHandleOption(OrderHandle.getHandleOption(orderDetailOrderInfo.getStatus(),comment));
        orderDetailVO.setOrderInfo(orderDetailOrderInfo);
        orderDetailVO.setOrderGoods(marketOrderMapper.orderDetail(orderId));

        return orderDetailVO;
    }

    @Override
    @Transactional
    public void orderDelete(Integer orderId) {
        marketOrderMapper.orderDeleted(orderId);
    }

    @Override
    @Transactional
    public void orderCancel(Integer orderId) {

        marketOrderMapper.OrderCancel(orderId);
    }

    @Override
    @Transactional
    public void orderConfirm(Integer orderId) {
        Date date = new Date();
        marketOrderMapper.orderConfirm(orderId,date);
    }

    @Override
    @Transactional
    public void orderRefund(Integer orderId) {
        Double price = marketOrderMapper.selectActualPrice(orderId);
        marketOrderMapper.orderRefund(orderId,new Date(),REFUND_TYPE,price);
    }

    @Override
    public OrderGoodsVO orderGoods(String orderId, String goodsId) {
       return marketOrderMapper.orderGoods(orderId,goodsId);
    }

    @Override
    @Transactional
    public void orderComment(OrderCommentBO orderComment) {
        //根据orderGoodsId查出goods表主键，
        OrderCommentPO orderCommentPO = marketOrderMapper.selectGoodsKey(orderComment.getOrderGoodsId());
        // 根据主键查询出goodsId，和 order_id,以及userId
        Integer orderId = orderCommentPO.getOrderId();
        Integer goodsId = orderCommentPO.getGoodsId();
        Integer userId = orderCommentPO.getUserId();
        // 插入comment表
//        marketOrderGoodsMapper.selectByPrimaryKey()
        MarketCommentExample marketCommentExample = new MarketCommentExample();
        MarketComment marketComment = new MarketComment();
        marketComment.setValueId(goodsId);
        marketComment.setContent(orderComment.getContent());
        marketComment.setUserId(userId);
        marketComment.setHasPicture(orderComment.getHasPicture());
        marketComment.setPicUrls(orderComment.getPicUrls());
        marketComment.setStar( orderComment.getStar());
        marketComment.setAddTime(new Date());
        marketComment.setUpdateTime(new Date());
        int i = marketCommentMapper.insertSelective(marketComment);
        Integer commentId = marketComment.getId();

        //更新ordergoods表
        marketOrderMapper.orderComment(orderComment.getOrderGoodsId(),commentId,new Date());
        //更新order表待评论数据
        MarketOrder marketOrder = marketOrderMapper.selectByPrimaryKey(orderId);
        int comments = marketOrder.getComments();
        if (comments>0){
            comments = comments - 1;
            marketOrderMapper.updateComments(comments,orderId);
        }

    }

    @Override
    @Transactional
    public OrderSubmitVO orderSubmit(OrderSubmitBO orderSubmitBO) {
//        //根据BOid获取对象
//
//        OrderSubmitVO orderSubmitVO = new OrderSubmitVO();
//
//        //团购规则信息👉团购规则id
//        MarketGrouponRules marketGrouponRules = marketGrouponRulesMapper.selectByPrimaryKey(orderSubmitBO.getGrouponRulesId());
//
//        //todo:carId=0;表示有多条数据，cartId不为0根据subject获取用户id查询cart表check标记位为1的所有数据数据
//        //todo：思路先写好cartId有具体值的逻辑，多条数据遍历执行一条数据的逻辑
//        MarketUser principal = (MarketUser) SecurityUtils.getSubject().getPrincipal();
//        Integer cartId = orderSubmitBO.getCartId();
//        if (cartId != 0){
//            //购物车信息👉购物车id
//            MarketCart marketCart = marketCartMapper.selectByPrimaryKey(orderSubmitBO.getCartId());
//
//            //地址信息👉地址id
//            MarketAddress marketAddress = marketAddressMapper.selectByPrimaryKey(orderSubmitBO.getAddressId());
//
//            //有慧娟信息👉优惠卷id
//            MarketCoupon marketCoupon = marketCouponMapper.selectByPrimaryKey(orderSubmitBO.getCouponId());
//
//            //用户优惠卷信息👉用户优惠卷id
//            MarketCouponUser marketCouponUser = marketCouponUserMapper.selectByPrimaryKey(orderSubmitBO.getUserCouponId());
//
//            //
//
//
//            MarketOrder marketOrder = new MarketOrder();
//            marketOrder.setUserId(principal.getId());
//            //订单编号获取时间戳
//            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
//            String format = simpleDateFormat.format(new Date());
//            marketOrder.setOrderSn(format);
//            marketOrder.setOrderStatus((short) 201);
//            marketOrder.setAftersaleStatus((short) 0);
//            marketOrder.setConsignee(marketAddress.getName());
//            marketOrder.setMobile(marketAddress.getTel());
//            marketOrder.setAddress(marketAddress.getProvince()+marketAddress.getCity()+marketAddress.getCounty()+marketAddress.getAddressDetail());
//            marketOrder.setMessage(orderSubmitBO.getMessage());
//            marketOrder.setGoodsPrice(marketCart.getPrice());
//            BigDecimal bigDecimal = new BigDecimal(0.0);
//            marketOrder.setCouponPrice(bigDecimal);
//            marketOrder.setOrderPrice(marketCart.getPrice());
//            marketOrder.setActualPrice(marketCart.getPrice());
//            marketOrder.setPayId(format);
//            marketOrder.setPayTime(new Date());
//            marketOrder.setAddTime(new Date());
//            marketOrder.setUpdateTime(new Date());
//            marketOrder.setDeleted(false);
//            marketOrder.setFreightPrice(bigDecimal);
//            marketOrder.setIntegralPrice(bigDecimal);
//            marketOrder.setGrouponPrice(bigDecimal);
//            marketOrderMapper.insertSelective(marketOrder);
//            Integer marketOrderId = marketOrder.getId();

//            //todo 获取商品表数据
//            //marketGoodsMapper.selectByPrimaryKey()
//
//            MarketOrderGoods marketOrderGoods = new MarketOrderGoods();
//            marketOrderGoods.setOrderId(marketOrderId);
//            marketOrderGoods.setGoodsId(marketCart.getGoodsId());
//            marketOrderGoods.setGoodsName(marketCart.getGoodsName());
//            marketOrderGoods.setGoodsSn(marketCart.getGoodsSn());
//            marketOrderGoods.setProductId(marketCart.getProductId());
//            marketOrderGoods.setNumber(marketCart.getNumber());
//            marketOrderGoods.setPrice(marketCart.getPrice());
//            marketOrderGoods.setSpecifications(new String[]{});
//            marketOrderGoods.setPicUrl(marketCart.getPicUrl());
//            marketOrderGoods.setComment(0);
//            marketOrderGoods.setAddTime(new Date());
//            marketOrderGoods.setUpdateTime(new Date());
//            marketOrderGoods.setDeleted(false);
//            marketOrderGoodsMapper.insertSelective(marketOrderGoods);
//            orderSubmitVO.setOrderId(marketOrderId);
//            orderSubmitVO.setGrouponLinkId(0);
//        }else {
//            Integer id = principal.getId();
//            MarketCartExample marketCartExample = new MarketCartExample();
//            MarketCartExample.Criteria criteria = marketCartExample.createCriteria();
//             criteria.andUserIdEqualTo(id);
//             criteria.andCheckedEqualTo(true);
//            List<MarketCart> marketCarts = marketCartMapper.selectByExample(marketCartExample);
//
//
//            for (MarketCart marketCart : marketCarts) {
//
//                MarketAddress marketAddress = marketAddressMapper.selectByPrimaryKey(orderSubmitBO.getAddressId());
//
//                //有慧娟信息👉优惠卷id
//                MarketCoupon marketCoupon = marketCouponMapper.selectByPrimaryKey(orderSubmitBO.getCouponId());
//
//                //用户优惠卷信息👉用户优惠卷id
//                MarketCouponUser marketCouponUser = marketCouponUserMapper.selectByPrimaryKey(orderSubmitBO.getUserCouponId());
//
//                //
//
//
//                MarketOrder marketOrder = new MarketOrder();
//                marketOrder.setUserId(principal.getId());
//                //订单编号获取时间戳
//                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
//                String format = simpleDateFormat.format(new Date());
//                marketOrder.setOrderSn(format);
//                marketOrder.setOrderStatus((short) 201);
//                marketOrder.setAftersaleStatus((short) 0);
//                marketOrder.setConsignee(marketAddress.getName());
//                marketOrder.setMobile(marketAddress.getTel());
//                marketOrder.setAddress(marketAddress.getProvince()+marketAddress.getCity()+marketAddress.getCounty()+marketAddress.getAddressDetail());
//                marketOrder.setMessage(orderSubmitBO.getMessage());
//                marketOrder.setGoodsPrice(marketCart.getPrice());
//                BigDecimal bigDecimal = new BigDecimal(0.0);
//                marketOrder.setCouponPrice(bigDecimal);
//                marketOrder.setOrderPrice(marketCart.getPrice());
//                marketOrder.setActualPrice(marketCart.getPrice());
//                marketOrder.setPayId(format);
//                marketOrder.setPayTime(new Date());
//                marketOrder.setAddTime(new Date());
//                marketOrder.setUpdateTime(new Date());
//                marketOrder.setDeleted(false);
//                marketOrder.setFreightPrice(bigDecimal);
//                marketOrder.setIntegralPrice(bigDecimal);
//                marketOrder.setGrouponPrice(bigDecimal);
//
//                marketOrderMapper.insert(marketOrder);
//                Integer marketOrderId = marketOrder.getId();
//
//                //todo 获取商品表数据
//                //marketGoodsMapper.selectByPrimaryKey()
//
//                MarketOrderGoods marketOrderGoods = new MarketOrderGoods();
//                marketOrderGoods.setOrderId(marketOrderId);
//                marketOrderGoods.setGoodsId(marketCart.getGoodsId());
//                marketOrderGoods.setGoodsName(marketCart.getGoodsName());
//                marketOrderGoods.setGoodsSn(marketCart.getGoodsSn());
//                marketOrderGoods.setProductId(marketCart.getProductId());
//                marketOrderGoods.setNumber(marketCart.getNumber());
//                marketOrderGoods.setPrice(marketCart.getPrice());
//                marketOrderGoods.setSpecifications(new String[]{});
//                marketOrderGoods.setPicUrl(marketCart.getPicUrl());
//                marketOrderGoods.setComment(0);
//                marketOrderGoods.setAddTime(new Date());
//                marketOrderGoods.setUpdateTime(new Date());
//                marketOrderGoods.setDeleted(false);
//                marketOrderGoodsMapper.insertSelective(marketOrderGoods);
//                orderSubmitVO.setOrderId(marketOrderId);
//                orderSubmitVO.setGrouponLinkId(0);
//
//            }
//        }
        OrderSubmitVO orderSubmitVO = new OrderSubmitVO();
        //判断userid是否为0
        List<MarketCart> marketCarts = null;
        MarketUser principal = (MarketUser) SecurityUtils.getSubject().getPrincipal();

        if (orderSubmitBO.getCartId() == 0){
            //数据库cart表查询
            MarketCartExample marketCartExample = new MarketCartExample();
            MarketCartExample.Criteria criteria = marketCartExample.createCriteria();
            criteria.andUserIdEqualTo(principal.getId());
            criteria.andCheckedEqualTo(true);
            criteria.andDeletedEqualTo(false);
            marketCarts = marketCartMapper.selectByExample(marketCartExample);
        }else {
            MarketCartExample marketCartExample = new MarketCartExample();
            MarketCartExample.Criteria criteria = marketCartExample.createCriteria();
            criteria.andIdEqualTo(orderSubmitBO.getCartId());

            marketCarts = marketCartMapper.selectByExample(marketCartExample);
        }
        //遍历获得订单总价格
        BigDecimal bigDecimal = BigDecimal.ZERO;
        for (MarketCart marketCart : marketCarts) {
//           bigDecimal.add(marketCart.getPrice());
            BigDecimal price = marketCart.getPrice();
            bigDecimal = bigDecimal.add(price);
        }
        //插入order表
//        MarketCart marketCart = marketCartMapper.selectByPrimaryKey(orderSubmitBO.getCartId());

        //地址信息👉地址id
        MarketAddress marketAddress = marketAddressMapper.selectByPrimaryKey(orderSubmitBO.getAddressId());

        //有慧娟信息👉优惠卷id
//        MarketCoupon marketCoupon = marketCouponMapper.selectByPrimaryKey(orderSubmitBO.getCouponId());

        //用户优惠卷信息👉用户优惠卷id
//        MarketCouponUser marketCouponUser = marketCouponUserMapper.selectByPrimaryKey(orderSubmitBO.getUserCouponId());

        //


        MarketOrder marketOrder = new MarketOrder();
        marketOrder.setUserId(principal.getId());
        //订单编号获取时间戳
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        String format = simpleDateFormat.format(new Date());
        marketOrder.setOrderSn(format);
        marketOrder.setOrderStatus((short) 101);
        marketOrder.setAftersaleStatus((short) 0);
        marketOrder.setConsignee(marketAddress.getName());
        marketOrder.setMobile(marketAddress.getTel());
        marketOrder.setAddress(marketAddress.getProvince()+marketAddress.getCity()+marketAddress.getCounty()+marketAddress.getAddressDetail());
        marketOrder.setMessage(orderSubmitBO.getMessage());
        marketOrder.setGoodsPrice(bigDecimal);
        //优惠卷减免
//        MarketCoupon marketCoupon1 = marketCouponMapper.selectByPrimaryKey(orderSubmitBO.getCouponId());
//        BigDecimal discount = marketCoupon1.getDiscount();
//        BigDecimal min = marketCoupon1.getMin();
//        if(min.compareTo(bigDecimal) == -1){
//            marketOrder.setCouponPrice(new BigDecimal(0));
//            marketOrder.setOrderPrice(bigDecimal);
//            marketOrder.setActualPrice(bigDecimal);
//        }else {
//            marketOrder.setGrouponPrice(discount);
//            marketOrder.setOrderPrice(bigDecimal.subtract(discount));
//            marketOrder.setActualPrice(bigDecimal.subtract(discount));
//        }
        //todo 查询系统表获取订单包邮配置
        MarketSystemExample marketSystemExample = new MarketSystemExample();
        MarketSystemExample.Criteria criteria1 = marketSystemExample.createCriteria();
        criteria1.andKeyNameIn(Arrays.asList(Count.MALL_SYSTEM_EXPRESS_FREIGHT_MIN,Count.MALL_SYSTEM_EXPRESS_FREIGHT_VALUE));
        List<MarketSystem> marketSystems = marketSystemMapper.selectByExample(marketSystemExample);
        String min = "";//最低订单费用包邮
        String value ="";//邮费
        for (MarketSystem marketSystem : marketSystems) {
            if (marketSystem.getKeyName().equals(Count.MALL_SYSTEM_EXPRESS_FREIGHT_VALUE)){
                value = marketSystem.getKeyValue();
            }
            if (marketSystem.getKeyName().equals(Count.MALL_SYSTEM_EXPRESS_FREIGHT_MIN)){
                min = marketSystem.getKeyValue();
            }
        }
        BigDecimal  minPrice = new BigDecimal(min);
        BigDecimal postage = new BigDecimal(value);
        //todo判断设置订单费用
        if (minPrice.compareTo(bigDecimal) == -1){
            marketOrder.setOrderPrice(bigDecimal);
            marketOrder.setFreightPrice(new BigDecimal(0));
            marketOrder.setActualPrice(bigDecimal.add(postage));
        }else {
            bigDecimal = bigDecimal.add(postage);
            marketOrder.setOrderPrice(bigDecimal);
            marketOrder.setFreightPrice(postage);
            marketOrder.setActualPrice(bigDecimal);
        }
        //todo 优惠卷减免
        if (orderSubmitBO.getCouponId() != null && orderSubmitBO.getCouponId() != 0){
            MarketCoupon marketCoupon = marketCouponMapper.selectByPrimaryKey(orderSubmitBO.getCouponId());
            BigDecimal discount = marketCoupon.getDiscount();
            bigDecimal = bigDecimal.subtract(discount);
            marketOrder.setOrderPrice(bigDecimal);
            marketOrder.setCouponPrice(marketCoupon.getDiscount());
            bigDecimal = bigDecimal.subtract(marketCoupon.getDiscount());
            marketOrder.setActualPrice(bigDecimal);
        }

        marketOrder.setGrouponPrice(new BigDecimal(0));
        //todo：实际付费等于商品费用加上邮费

        marketOrder.setPayId(format);
        marketOrder.setPayTime(new Date());
        marketOrder.setAddTime(new Date());
        marketOrder.setUpdateTime(new Date());
        marketOrder.setDeleted(false);
        marketOrder.setIntegralPrice(new BigDecimal(0));
        marketOrder.setGrouponPrice(new BigDecimal(0));
        marketOrder.setCouponPrice(new BigDecimal(0));
        marketOrder.setComments((short)marketCarts.size());
        marketOrderMapper.insert(marketOrder);
        Integer marketOrderId = marketOrder.getId();
        for (MarketCart marketCart1 : marketCarts) {

            //todo 获取商品表数据
            //marketGoodsMapper.selectByPrimaryKey()

            MarketOrderGoods marketOrderGoods = new MarketOrderGoods();
            marketOrderGoods.setOrderId(marketOrderId);
            marketOrderGoods.setGoodsId(marketCart1.getGoodsId());
            marketOrderGoods.setGoodsName(marketCart1.getGoodsName());
            marketOrderGoods.setGoodsSn(marketCart1.getGoodsSn());
            marketOrderGoods.setProductId(marketCart1.getProductId());
            marketOrderGoods.setNumber(marketCart1.getNumber());
            marketOrderGoods.setPrice(marketCart1.getPrice());
            marketOrderGoods.setSpecifications(new String[]{marketCart1.getSpecifications()});
            marketOrderGoods.setPicUrl(marketCart1.getPicUrl());
            marketOrderGoods.setComment(0);
            marketOrderGoods.setAddTime(new Date());
            marketOrderGoods.setUpdateTime(new Date());
            marketOrderGoods.setDeleted(false);
            marketOrderGoodsMapper.insert(marketOrderGoods);

        }

        orderSubmitVO.setOrderId(marketOrderId);
        orderSubmitVO.setGrouponLinkId(0);
        //逻辑删除购物车
        MarketCartExample marketCartExample = new MarketCartExample();
        MarketCartExample.Criteria criteria = marketCartExample.createCriteria();
        ArrayList<Integer> cartIds = new ArrayList<>();
        for (int i = 0; i < marketCarts.size(); i++) {
            cartIds.add(marketCarts.get(i).getId());
        }
        criteria.andIdIn(cartIds);
        MarketCart marketCart1 = new MarketCart();
        marketCart1.setDeleted(true);
        marketCartMapper.updateByExampleSelective(marketCart1,marketCartExample);

        return orderSubmitVO;
    }
}
